<?php session_start();
validaAcesso();
echo "<h2>Alterar ".$_SESSION["menu"]["alt"][12]." da UH: {$_SESSION["NOME_HOSTEL_"]}</h2>";


require_once"funcoes/hostel_habitacao.jsp";


if(isset($_GET[atualiza])==1){

	
	/*
	echo"<pre>";
	print_r($_POST);
	echo"</pre>";
	*/
	
	
	
	$ids_tp_habitacao = "";
	$lotacao = 1;
	for ($n=0; $n < $_POST["pnum_tp_habitacao"]; $n++){

		if ($_POST["pid_tp_habitacao"][$n] !== null) {
			$id_tp_h = $_POST["pid_tp_habitacao"][$n];
			$ids_tp_habitacao .= $id_tp_h."-";
			
			if ($_POST["plotacao$id_tp_h"] > $lotacao) {
				$lotacao = $_POST["plotacao$id_tp_h"];
			}
		}
	}

	
	setHabitacao($_POST["pcodigo"], $_POST["pnum_habitacao"], $ids_tp_habitacao, $lotacao, $_POST["pid_bloco"], $_SESSION["ID_HOSTEL_"], $_POST["pleitos_extra"]);

	
}

if ($_REQUEST["pcodigo"]) {	

	$field = getHabitacao($_REQUEST["pcodigo"],"input");
?>



<form method="POST" action="index.jsp?atualiza=1&alt=12" autocomplete="off">


<input type="hidden" name="pcodigo" value="<?php echo $_REQUEST["pcodigo"];?>">


<div class='item'><h5>Bloco:</h5>
<select name="pid_bloco">
<?php
require_once"funcoes/hostel_bloco.jsp";
getBloco($field[3],"select");
?>
</select>
 <b id='ok'>*</b></div>
 <br>

<div class='item'><h5>N&uacute;mero da Habita&ccedil;&atilde;o / Quarto:</h5>
<input type="text" size="5" maxlength="5" name="pnum_habitacao" value="<?php echo $field[1]; ?>"> Ex: 02, 111</div>

<br>

<div class='item'><h5>Tipo de Habita&ccedil;&atilde;o:</h5>
<?php
require_once"funcoes/hostel_tp_habitacao.jsp";
getTpHabitacao($field[2],"checkbox");
?>
</div>
<br>

<!--<div class='item'><h5>N&uacute;mero de Leitos:</h5>
<input type="text" size="3" maxlength="2" name="plotacao"  value="<?php echo $field[3]; ?>"> Ex: 2 (casal), 2 (beliche)</div>-->
<div class='item'><h5>N&uacute;mero de Leitos Extra:</h5>
<input type="text" size="3" maxlength="2" name="pleitos_extra"  value="<?php echo $field[5]; ?>"> Ex: 1 (ber&ccedil;o / cama extra)</div>
<br>


<div class='item'><h5> </h5><input type="submit" value="alterar"></div>

</form>


<?php
}
getHabitacao(0,"lista");
?>